<template>
  <div class="add-wallet">
    <el-dialog
      :title="visible.type===0? '添加钱包':'修改钱包'"
      :visible.sync="visible.showSetDialog"
      width="600px"
      center
      :close-on-click-modal="false"
    >
      <div class="content">
        <div class="line flex-left">
          <label class="title">平台名称</label>
          <el-input v-model="param.name" size="medium" placeholder="请输入平台名称"></el-input>
        </div>
        <div class="line flex-left">
          <label class="title">下载链接</label>
          <el-input v-model="param.download_url" size="medium" placeholder="请输入下载链接"></el-input>
        </div>
        <div class="line flex-left">
          <label class="title">分享简介</label>
          <el-input
            v-model="param.introduce"
            size="medium"
            placeholder="请输入分享简介信息"
            type="textarea"
            :rows="6"
          ></el-input>
        </div>
        <div class="line flex-left">
          <label class="title">关于我们</label>
          <el-input
            v-model="param.summary"
            size="medium"
            placeholder="请输入关于我们信息"
            type="textarea"
            :rows="6"
          ></el-input>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="visible.showSetDialog = false">取 消</el-button>
        <el-button
          size="small"
          type="primary"
          @click="submit"
          :disabled="onSubmit"
          :loading="onSubmit"
        >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  createWallet,
  updateWallet
} from "../../views/WalletManage/Wallet.service.js";
export default {
  props: ["visible"],
  data() {
    return {
      param: {
        name: "",
        download_url: "",
        introduce: "",
        summary: ""
      },
      onSubmit: false
    };
  },
  watch: {
    visible: {
      handler(item) {
        if (item.type === 1) this.param = { ...this.param, ...item.data };
        if (item.showSetDialog === false)
          this.param = {
            name: "",
            download_url: "",
            introduce: ""
          };
      },
      deep: true
    }
  },
  methods: {
    async submit() {
      const res =
        this.visible.type === 0
          ? await createWallet(this.param)
          : await updateWallet(this.param);
      if (res.code === 0) {
        this.$notify.success({
          title: "提示",
          message: this.visible.type === 0 ? "添加成功" : "修改成功"
        });
        this.$emit("success");
      }
    }
  }
};
</script>

<style lang="scss">
.add-wallet {
  .el-dialog__header {
    border-bottom: 1px solid #e9e9e9;
    padding: 15px;
    font-weight: 600;
  }
  .content {
    .line {
      // height: 60px;
      margin-bottom: 20px;
      .title {
        width: 6em;
        text-align: right;
        margin-right: 20px;
        flex-shrink: 0;
      }
    }
  }
}
</style>